package com.origin.ebuy.forg.web.controller.user;

import com.origin.ebuy.bargd.service.user.IUserService;
import com.origin.ebuy.bargd.service.user.impl.UserServiceImpl;
import com.origin.ebuy.forg.web.BaseServlet;
import java.io.IOException;
import java.sql.SQLException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 
 * 更新用户的角色
 * Servlet implementation class UpdateRoleServlet
 */
public class UpdateRoleServlet extends BaseServlet {
	private static final long serialVersionUID = 1L;

    /**
     * Default constructor. 
     */
    public UpdateRoleServlet() {
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		super.doPost(request, response);
		IUserService service = new UserServiceImpl();
		String id = request.getParameter("id");
		String type = request.getParameter("type");
		//修改用户的角色
		if("2".equals(type)){
			String rule = request.getParameter("rule");
			try {
				service.updateUserRole(id, rule);
			} catch (SQLException e) {
				e.printStackTrace();
			}
			
		//修改用户的状态
		}else if("1".equals(type)){
			String state = request.getParameter("state");
			try {
				service.updateUserState(id, state);
			} catch (SQLException e) {
				e.printStackTrace();
			}
			
		}
		
	}

}
